﻿// JSON C# Class Generator
// http://at-my-window.blogspot.com/?page=json-class-generator

using System;
using Newtonsoft.Json.Linq;
using JsonCSharpClassGenerator;
using TomatoSynchronizer.Store;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;

namespace TomatoSynchronizer.Entities 
{

    public class Article 
    {
    	public override bool Equals(object obj)
		{
			if(obj is Article)
			{
				Article info = (Article)obj;
				
				if(info.articles_order  == _articles_order && info.articles_status == _articles_status)
				{
					MappingStore mappingStore = new MappingStore(store.site,info.store.site,"languages_id");
					
					foreach(Mapping mapping in mappingStore.Mappings)
					{
						try
						{							
							if(_articles_descriptions["articles_description[" + mapping.SrcValue + "]"] != info.articles_descriptions["articles_description[" + mapping.DestValue + "]"])
							{
								return false;
							}
							
							if(_articles_names["articles_name[" + mapping.SrcValue + "]"] != info.articles_names["articles_name[" + mapping.DestValue + "]"])
							{
								return false;
							}	
							
							if(_articles_urls["articles_url[" + mapping.SrcValue + "]"] != info.articles_urls["articles_url[" + mapping.DestValue + "]"])
							{
								return false;
							}
							
							if(_meta_descriptions["meta_description[" + mapping.SrcValue + "]"] != info.meta_descriptions["meta_description[" + mapping.DestValue + "]"])
							{
								return false;
							}
							
							if(_meta_keywordss["meta_keywords[" + mapping.SrcValue + "]"] != info.meta_keywordss["meta_keywords[" + mapping.DestValue + "]"])
							{
								return false;
							}
							
							if(_page_titles["page_title[" + mapping.SrcValue + "]"] != info.page_titles["page_title[" + mapping.DestValue + "]"])
							{
								return false;
							}
						}
						catch(KeyNotFoundException ex)
						{
							throw ex;
						}
					}
					return true;
				}
			}
			
			return false;
		}
    	
        public Article()
        {
        }

        public Article(string json)
         : this(JObject.Parse(json))
        {
        }

        private JObject __jobject;
        public Article(JObject obj)
        {
            this.__jobject = obj;
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        private ArticleStore store;

        public ArticleStore Store
        {
           get{
            return store;}
           set{
            store = value;}
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private string _articles_id;
        public string articles_id
        {
            get
            {
                if(_articles_id == null)
                    _articles_id = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "articles_id"));
                return _articles_id;
            }
            set
            {
                _articles_id = value;
            }
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private string _articles_categories_id;
        public string articles_categories_id
        {
            get
            {
                if(_articles_categories_id == null)
                    _articles_categories_id = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "articles_categories_id"));
                return _articles_categories_id;
            }
            set
            {
                _articles_categories_id = value;
            }
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private string _articles_status;
        public string articles_status
        {
            get
            {
                if(_articles_status == null)
                    _articles_status = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "articles_status"));
                return _articles_status;
            }
            set
            {
                _articles_status = value;
            }
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private string _articles_order;
        public string articles_order
        {
            get
            {
                if(_articles_order == null)
                    _articles_order = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "articles_order"));
                return _articles_order;
            }
            set
            {
                _articles_order = value;
            }
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private string _articles_date_added;
        public string articles_date_added
        {
            get
            {
                if(_articles_date_added == null)
                    _articles_date_added = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "articles_date_added"));
                return _articles_date_added;
            }
            set
            {
                _articles_date_added = value;
            }
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private string _articles_last_modified;
        public string articles_last_modified
        {
            get
            {
                if(_articles_last_modified == null)
                    _articles_last_modified = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "articles_last_modified"));
                return _articles_last_modified;
            }
            set
            {
                _articles_last_modified = value;
            }
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private object _articles_image;
        public object articles_image
        {
            get
            {
                if(_articles_image == null)
                    _articles_image = JsonClassHelper.ReadObject(JsonClassHelper.GetJToken<JToken>(__jobject, "articles_image"));
                return _articles_image != null ? _articles_image : string.Empty;
            }
            set
            {
                _articles_image = value;
            }
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private string _language_id;
        public string language_id
        {
            get
            {
                if(_language_id == null)
                    _language_id = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "language_id"));
                return _language_id;
            }
            set
            {
                _language_id = value;
            }
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private string _articles_name;
        public string articles_name
        {
            get
            {
                if(_articles_name == null)
                    _articles_name = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "articles_name"));
                return _articles_name;
            }
            set
            {
                _articles_name = value;
            }
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private string _articles_url;
        public string articles_url
        {
            get
            {
                if(_articles_url == null)
                    _articles_url = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "articles_url"));
                return _articles_url;
            }
            set
            {
                _articles_url = value;
            }
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private string _articles_description;
        public string articles_description
        {
            get
            {
                if(_articles_description == null)
                    _articles_description = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "articles_description"));
                return _articles_description;
            }
            set
            {
                _articles_description = value;
            }
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private string _articles_page_title;
        public string articles_page_title
        {
            get
            {
                if(_articles_page_title == null)
                    _articles_page_title = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "articles_page_title"));
                return _articles_page_title;
            }
            set
            {
                _articles_page_title = value;
            }
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private string _articles_meta_keywords;
        public string articles_meta_keywords
        {
            get
            {
                if(_articles_meta_keywords == null)
                    _articles_meta_keywords = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "articles_meta_keywords"));
                return _articles_meta_keywords;
            }
            set
            {
                _articles_meta_keywords = value;
            }
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private string _articles_meta_description;
        public string articles_meta_description
        {
            get
            {
                if(_articles_meta_description == null)
                    _articles_meta_description = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "articles_meta_description"));
                return _articles_meta_description;
            }
            set
            {
                _articles_meta_description = value;
            }
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private Dictionary<string, string> _articles_names;
		public Dictionary<string, string> articles_names
		{
			get
			{
				if(_articles_names == null)
				{
					_articles_names = new Dictionary<string, string>();
					
					if(__jobject != null)
					{
						if(store != null)
						{
							var languages = store.site.GetLanguageStore().LoadItems();
							
							foreach(Language language in languages)
							{
								_articles_names["articles_name[" + language.languages_id + "]"] = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject,"articles_name[" + language.languages_id + "]"));
							}
						}
					}
				}
				
				return _articles_names;
			}
			set
			{
				_articles_names = value;
			}
		}

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private Dictionary<string, string> _articles_urls;
		public Dictionary<string, string> articles_urls
		{
			get
			{
				if(_articles_urls == null)
				{
					_articles_urls = new Dictionary<string, string>();
					
					if(__jobject != null)
					{
						if(store != null)
						{
							var languages = store.site.GetLanguageStore().LoadItems();
							
							foreach(Language language in languages)
							{
								_articles_urls["articles_url[" + language.languages_id + "]"] = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject,"articles_url[" + language.languages_id + "]"));
							}
						}
					}
				}
				
				return _articles_urls;
			}
			set
			{
				_articles_urls = value;
			}
		}

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private Dictionary<string, string> _articles_descriptions;
		public Dictionary<string, string> articles_descriptions
		{
			get
			{
				if(_articles_descriptions == null)
				{
					_articles_descriptions = new Dictionary<string, string>();
					
					if(__jobject != null)
					{
						if(store != null)
						{
							var languages = store.site.GetLanguageStore().LoadItems();
							
							foreach(Language language in languages)
							{
								_articles_descriptions["articles_description[" + language.languages_id + "]"] = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject,"articles_description[" + language.languages_id + "]"));
							}
						}
					}
				}
				
				return _articles_descriptions;
			}
			set
			{
				_articles_descriptions = value;
			}
		}

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private Dictionary<string, string> _page_titles;
		public Dictionary<string, string> page_titles
		{
			get
			{
				if(_page_titles == null)
				{
					_page_titles = new Dictionary<string, string>();
					
					if(__jobject != null)
					{
						if(store != null)
						{
							var languages = store.site.GetLanguageStore().LoadItems();
							
							foreach(Language language in languages)
							{
								_page_titles["page_title[" + language.languages_id + "]"] = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject,"page_title[" + language.languages_id + "]"));
							}
						}
					}
				}
				
				return _page_titles;
			}
			set
			{
				_page_titles = value;
			}
		}

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private Dictionary<string, string> _meta_keywordss;
		public Dictionary<string, string> meta_keywordss
		{
			get
			{
				if(_meta_keywordss == null)
				{
					_meta_keywordss = new Dictionary<string, string>();
					
					if(__jobject != null)
					{
						if(store != null)
						{
							var languages = store.site.GetLanguageStore().LoadItems();
							
							foreach(Language language in languages)
							{
								_meta_keywordss["meta_keywords[" + language.languages_id + "]"] = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject,"meta_keywords[" + language.languages_id + "]"));
							}
						}
					}
				}
				
				return _meta_keywordss;
			}
			set
			{
				_meta_keywordss = value;
			}
		}

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private Dictionary<string, string> _meta_descriptions;
		public Dictionary<string, string> meta_descriptions
		{
			get
			{
				if(_meta_descriptions == null)
				{
					_meta_descriptions = new Dictionary<string, string>();
					
					if(__jobject != null)
					{
						if(store != null)
						{
							var languages = store.site.GetLanguageStore().LoadItems();
							
							foreach(Language language in languages)
							{
								_meta_descriptions["meta_description[" + language.languages_id + "]"] = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject,"meta_description[" + language.languages_id + "]"));
							}
						}
					}
				}
				
				return _meta_descriptions;
			}
			set
			{
				_meta_descriptions = value;
			}
		}               
    }
}
